<extend name="Public/base"/>
<block name="body">
  <!-- 标题栏 -->
  
  <div class="main-title">
    <h2>商品列表</h2>
  </div>
  <div class="tools"> <a class="btn" href="{:U('Goods/add')}">新 增</a> 
    
    <!-- 高级搜索 -->
    <div class="search-form fr cf">
      <div class="sleft">
        <input type="text" name="title" class="search-input" value="{:I('title')}" placeholder="请输入商品名称">
        <a class="sch-btn" href="javascript:;" id="search" url="{:U('goods/index')}"><i class="btn-search"></i></a> </div>
    </div>
  </div>
  
  <!-- 数据列表 -->
  <div class="data-table category">
    <div class="data-table table-stripe">
      <table class="">
        <thead>
          <tr>
            <th class="">编号</th>
            <th>图像</th>
            <th class="">名称</th>
            <th class="">价格</th>
            <th class="">库存</th>
            <th class="">描述</th>
            <th class="">状态</th>
            <th class="">操作</th>
          </tr>
        </thead>
        <tbody class="">
          <notempty name="_list">
          <volist name="_list" id="vo">
   
            <tr id="{$vo.id}">
                <td>{$vo.id} </td>
                <td><img src="{$vo['cover_id']|get_cover='path'}" width="60"/></td>
                <td>{$vo.title}</td>
                <td><input type="text" name="price" class="text" value="{$vo.price}" style="width:100px;"></td>
                <td><input type="text" name="stock" class="text" value="{$vo.stock}" style="width:100px;"></td>
                <td>{$vo.description}</td>
                <td>{$vo['status']?'正常':'已下架'}</td>
                <td><a href="{:U('Goods/edit', 'id='.$vo['id'])}">编辑</a> <a href="{:U('Goods/setstatus?ids='.$vo['id'].'&status='.abs(1-$vo['status']))}" class="ajax-get">{$vo.status|show_goods_status_op}</a> <a class="confirm ajax-get" href="{:U('Goods/setStatus', 'status=-1&ids='.$vo['id'])}">删除</a></td>
            </tr>
          </volist>
          <else/>
        <td colspan="8" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
            </tbody>
      </table>
    </div>
  </div>
  <div class="page"> {$_page} </div>
</block>
<block name="script">

  <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
  <script type="text/javascript">
  		(function($){
			/* 实时更新分类信息 */
		
			$(".category")
			   .on("focus","input",function(){
                    $(this).data('param',$(this).val());
                })
				
                .on("blur", "input", function(){
					   if($(this).data('param')!=$(this).val()){
							var id = $(this).parent().parent().parent().find('tr').attr('id');
							var v = $(this).val();
							var name = $(this).attr('name');
							var url = '{:U('Goods/ajaxPost')}';
							$.post(url, {id:id, val:v, field:name},function(data){
								 if (data.status==1) {
									updateAlert(data.info,'alert-success');
									 setTimeout(function(){
									if (data.url) {
										location.href=data.url;
									}else if( $(that).hasClass('no-refresh')){
										$('#top-alert').find('button').click();
									}else{
										location.reload();
									}
									},1500);
								}else{
									updateAlert(data.info);
									setTimeout(function(){
											$('#top-alert').find('button').click();
									},1500);
								}
							},'json')
						 }
                });
		})(jQuery);
		
  //搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
		//var status = $("#sch-sort-txt").attr("data");
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
		if(status != ''){
			query = 'status=' + status + "&" + query;
        }
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
 //回车自动提交
    $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });
    //导航高亮
    highlight_subnav('{:U('Goods/index')}');
</script>
</block>
